package com.kds.changzhou.handler;

import com.kds.changzhou.data.Gateway;
import com.kds.changzhou.message.inbound.PeriodMessage;
import com.kds.changzhou.netty.TcpClient;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.Attribute;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 孔德嵩
 * 创建日期 2023/12/11
 */
@Slf4j
public class PeriodHandler extends SimpleChannelInboundHandler<PeriodMessage> {


    private HandlerConfig handlerConfig;

    public PeriodHandler(HandlerConfig handlerConfig) {
        this.handlerConfig = handlerConfig;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, PeriodMessage msg) throws Exception {

        Attribute GATE_WAY = ctx.channel().attr(TcpClient.GATE_WAY_KEY);

        Gateway gateway = (Gateway) GATE_WAY.get();

        log.info("服务器返回对采集器[{}_{}]上传周期的设置：每{}分钟上传一次", gateway.getBuildingCode(), gateway.getGatewayId(), msg.getPeriod());
    }
}
